// pages/Main/my/my.js
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    myChildshow: false,
    alreadynum: false,
    classListshow: false,
    testManagementname: false,
    workManagementname: false,
    mayTestname: false,
    alreadytestname: false,
    todayJobname: false,
    weaknowledgename: false,
    misTopicname: false,
    learnLogname: false,
    testCollectionname: false,
    informationnname: false,
    colBooknname: false,
    setname: false,
    ture: true,
    gerenname: [],
    orgid: "",
    userid: "",
    weiduname: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var orgid = common.getStorageSync("orgid")
    var userid = common.getStorageSync("userid")
    this.setData({
      orgid: orgid,
      userid: userid,
    });

    this.PersonalCenter();
    console.log(userid);
    this.geren();

  },
  PersonalCenter: function () {
    let params = { "orgid": this.data.orgid, "peid": this.data.userid, "menuid": "" };
    //第三步 调用接口
    businessLogic.PersonalCenter(params, (res) => {
      for (let a = 0; a < res.length; a++) {
        //console.log(res[a].title);
        var x = "";
        switch (res[a].title) {
          case "我的孩子":
            this.setData({
              myChildshow: true
            });
            break;
          case "已绑定账号":
            this.setData({
              alreadynum: true
            });
            break;
          case "班级列表":
            this.setData({
              classListshow: true
            });
            break;
          case "试卷管理":
            this.setData({
              testManagementname: true
            });
            break;
          case "作业管理":
            this.setData({
              workManagementname: true
            });
            break;
          case "可参加作业":
            this.setData({
              mayTestname: true
            });
            break;
          case "已参加作业":
            this.setData({
              alreadytestname: true
            });
            break;
          case "今日作业":
            this.setData({
              todayJobname: true
            });
            break;
          case "薄弱知识点":
            this.setData({
              weaknowledgename: true
            });
            break;
          case "错题集":
            this.setData({
              misTopicname: true
            });
            break;
          case "学习日志":
            this.setData({
              learnLogname: true
            });
            break;
          case "试题收藏":
            this.setData({
              testCollectionname: true
            });
            break;
          case "消息":
            this.setData({
              informationnname: true
            });
            break;
          case "收藏":
            this.setData({
              colBooknname: true
            });
            break;
          case "设置":
            this.setData({
              setname: true
            });
            break;
          case "三大维度":
            this.setData({
              weiduname: true
            });
            break;
          default:
            x = "异常";
        }
        // console.log(x);

      }

    });
  }, geren: function () {
    // console.log(userid);    
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "id": this.data.userid };
    //第三步 调用接口
    businessLogic.QueryPersonal(params, (res) => {
      // console.log(res);
      common.setStorageSync("name", res.title);
      common.setStorageSync("role", res.type_dictionary_title);
      var role = res.type_dictionary_title;
      this.setData({
        gerenname: res,
        role: role
      });
    });
  }, myChild: function () {
    wx.navigateTo({
      url: "../myChild/myChild"
    });
  }, information: function () {
    wx.navigateTo({
      url: "../information/information?name=" + this.data.gerenname.type_dictionary_title
    });
  }, parents: function () {
    wx.navigateTo({
      url: "../browsing/browsing"
    });
  }, classList: function () {
    wx.navigateTo({
      url: "../classList/classList"
    });
  }, set: function () {
    wx.navigateTo({
      url: "../set/set"
    });
  }, colBook: function () {
    wx.navigateTo({
      url: "../colBook/colBook"
    });
  }, testManagement: function () {
    wx.navigateTo({
      url: "../testManagement/testManagement"
    });
  },
  workManagement: function () {
    wx.navigateTo({
      url: "../workManagement/workManagement"
    });
  }, mayTest: function () {
    wx.navigateTo({
      url: "../mayTest/mayTest"
    });
  }, alreadytest: function () {
    wx.navigateTo({
      url: "../alreadytest/alreadytest"
    });
  },
  todayJob: function () {
    // console.log(this.data.role);
    wx.navigateTo({
      url: "../todayJob/todayJob?id=" + this.data.role
    });
  },
  weaknowledge: function () {
    wx.navigateTo({
      url: "../weaknowledge/weaknowledge"
    });
  },
  misTopic: function () {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "peopleid,iscomplete,examtype", "searchValue": this.data.userid + ",0,1" }
    businessLogic.QueryPerson(params, (res) => {
      console.log(res)
      if(res==""||res==undefined){
        wx.navigateTo({
          url: "../misTopic/misTopic"
        });
      }else{
        common.showToast("你还有一场考试还未完成","none")
      }
    })
  },
  learnLog: function () {
    wx.navigateTo({
      url: "../learnLog/learnLog"
    });
  },
  testCollection: function () {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "peopleid,iscomplete,examtype", "searchValue": this.data.userid + ",0,1" }
    businessLogic.QueryPerson(params, (res) => {
      console.log(res)
      if (res == "" || res == undefined) {
        wx.navigateTo({
          url: "../testCollection/testCollection"
        });
      } else {
        common.showToast("你还有一场考试还未完成", "none")
      }
    })
   
  },
  boundcount: function () {
    wx.navigateTo({
      url: "../boundcount/boundcount"
    });
  },
  weidu: function () {
    common.showToast("小程序目前不支持", "none")
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
});